public class DoubleEquivalence {
    static void show(String desc, Double n1, Double n2) {
        System.out.println(desc + ":");
        System.out.printf("n1:%e, n2:%e n1==n2:%b n1.equals(n2):%b%n", n1, n2, n1 == n2, n1.equals(n2));
    }

    public static void test(double x1, double x2) {
        Double d1 = x1;
        Double d2 = x2;
        show("Doubles", d1, d2);

        Double n1 = new Double(x1);
        Double n2 = new Double(x2);
        show("Double objects", n1, n2);

        Double val1 = Double.valueOf(x1);
        Double val2 = Double.valueOf(x2);
        show("Double.valueOf", val1, val2);

    }

    public static void main(String[] args) {
        test(0, Double.MIN_VALUE);
        System.out.println("---------------------");
        test(Double.MAX_VALUE, Double.MAX_VALUE - Double.MIN_VALUE * 1_000_000);
    }
}
